<!-- 账户管理 -->
<template>
        <div class="fixedBox" v-show='checkShow'>
            <div class="popupCheckBox">
                <div class="popuplistBoxTop">
                    <div class="popuplistBoxTopFont">
                        确认要删除该角色吗？
                    </div>
                    <div class="popuplistBoxTopBut" @click='delectCancelClick()'>
                        <i class="icon font_family icon-chuangkouguanbi-dianji"></i>
                    </div>
                </div>
                <div class="popupCheckButton">
                    <div class="popupCheckPass" @click='delectOkClick()'>
                        确 认
                    </div>
                    <div class="popupCheckFail" @click='delectCancelClick()'>
                        取 消
                    </div>
                </div>
            </div>
        </div>
</template>
<script>
import taskRequest from "../../assets/task";
const crypto = require("crypto");
export default {
  data() {
    return {
      searchVal: "", //所搜
      dataList: [],
      currentPage: 10, //每页条数
      pageSize: 1, //页码
      totalVal: 0, //总数量
      checkShow: false, //删除弹框
      passwordBoxShow: false, //密码弹框
      editIndex: "", //修改index
      passwordVal: "", //密码
      passwordShow: false,
      passwordOkVal: "", //确认密码
      passwordOkShow: false
    };
  },
  filters: {},
  created: function() {
    var self = this;
    self.getList();
  },
  watch: {},
  mounted() {},
  methods: {
    //获取列表
    getList() {
      let self = this;
      taskRequest
        .adminListFun({
          page: self.pageSize,
          size: self.currentPage
        })
        .then(data => {
          if (data.statusCode == 200) {
            if (data.data.records) {
              self.dataList = data.data.records;
              self.totalVal = data.data.total;
            } else {
              self.$message(data.statusMessage);
            }
          } else {
            self.$message(data.statusMessage);
          }
        })
        .catch(msg => {
          self.$message("服务器异常");
        });
    },
    //搜索
    searchFun() {},
    //分页 - 每页条数
    handleSizeChange(val) {
      this.currentPage = val;
      this.getList();
    },
    //分页 - 页数
    handleCurrentChange(val) {
      this.pageSize = val;
      this.getList();
    },
    //重置密码
    passWordClick(index) {
      this.passwordBoxShow = true;
      this.editIndex = index;
    },
    //确认重置
    passwordAddClick() {
      let self = this;
      let reg = new RegExp("^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z_]{8,16}$");
      if (self.passwordVal.length < 8) {
        self.passwordShow = true;
        return;
      } else {
        if (reg.test(self.passwordVal)) {
          self.passwordShow = false;
        } else {
          self.passwordShow = true;
          return;
        }
      }
      if (self.passwordVal != self.passwordOkVal) {
        this.passwordOkShow = true;
        return;
      } else {
        this.passwordOkShow = false;
      }
      let possible = self.passwordOkVal;
      let shaCode = crypto.createHash("md5");
      let md5Str = shaCode.update(possible, "utf-8").digest("hex");
      taskRequest
        .adminResettingFun({
          code: self.dataList[self.editIndex].code,
          password: md5Str
        })
        .then(data => {
          if (data.data.statusCode == 200) {
            self.$message({
              showClose: true,
              message: "修改成功",
              type: "success"
            });
          } else {
            self.$message(data.statusMessage);
          }
        })
        .catch(msg => {
          self.$message("服务器异常");
        });
      self.passwordBoxShow = false;
    },
    //取消重置
    passwordCancelClick() {
      this.passwordBoxShow = false;
    },
    //添加
    addClick() {
      this.$router.push({
        path: `/home/account/edit?button=add`
      });
    },
    //编辑
    editClick(index) {
      this.$router.push({
        path: `/home/account/edit?button=edit&code=${this.dataList[index].code}`
      });
    },
    //删除
    delectClick(index) {
      this.checkShow = true;
      this.editIndex = index;
    },
    //确认删除
    delectOkClick() {
      let self = this;
      taskRequest
        .adminRoleDeleteFun({
          code: self.dataList[self.editIndex].code
        })
        .then(data => {
          if (data.statusCode == 200) {
            self.$message({
              showClose: true,
              message: "删除成功",
              type: "success"
            });
            self.getList();
          } else {
            self.$message(data.statusMessage);
          }
        })
        .catch(msg => {
          self.$message("服务器异常");
        });
      this.checkShow = false;
    },
    //取消删除
    delectCancelClick() {
      this.checkShow = false;
    }
  }
};
</script>
<style scoped>
.listOne {
  width: 18%;
}

.listTwo {
  width: 18%;
}

.listThree {
  width: 18%;
}

.listFour {
  width: 18%;
}

.listFive {
  width: 28%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.password {
  background: #279de2;
  padding: 0 14px;
}

.okbut {
  background: #279de2;
  margin: 0 14px;
}

.delect {
  background: #ed4a47;
}

.passwordBox {
  width: 700px;
  height: 430px;
  background: white;
  border-radius: 4px;
  margin: 200px auto;
  overflow: hidden;
}

.passwordTop {
  margin-bottom: 60px;
}

.passwordConter {
  width: 100%;
  height: 360px;
}

.passwordList {
  display: flex;
  line-height: 50px;
  margin: 20px 0 0 90px;
}

.passwordBut {
  margin-top: 80px;
  width: 100%;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.passwordAdd {
  width: 200px;
  height: 40px;
  line-height: 40px;
  font-size: 18px;
  background: linear-gradient(
    315deg,
    rgba(30, 145, 232, 1) 0%,
    rgba(67, 204, 255, 1) 100%
  );
}

.passwordCancel {
  width: 200px;
  height: 40px;
  line-height: 40px;
  font-size: 18px;
  color: #279de2 !important;
  border: 1px solid #279de2;
  margin: 0 20px;
}

.warnBox {
  width: 100%;
  height: 19px;
  margin-top: 4px;
  margin-bottom: -12px;
  text-align: center;
}
</style>